package main

import (
	"fmt"
)

func main() {
	arri := [5]int{1, 2, 3, 4, 5}
	for i := 0; i < len(arri); i++ {
		fmt.Printf("Array at index %d is %d\n", i, arri[i])
	}
	for i, v := range arri {
		fmt.Println("Array item", i, "is", v)
	}
	//var arrLazy = [...]int{5, 6, 7, 8, 22}
	//var arrLazy1 = []int{5, 6, 7, 8, 22}
	var arrKeyValue = [5]string{3: "Chris", 4: "Ron"} //设置index 3 4的值
	for i, v := range arrKeyValue {
		fmt.Println("Array item", i, "is", v)
	}
	var arrKeyValue1 = []string{1: "Chris", 3: "Ron"} //注：初始化得到的实际上是切片slice
	for i, v := range arrKeyValue1 {
		fmt.Println("Array item", i, "is", v)
	}

	arrf := [3]float64{1.1, 2.2, 3.3}
	sumF := Sum(&arrf)
	fmt.Printf("sum of arrf is %f\n", sumF)

	sliceArr := []int{1, 2, 3, 4, 5}
	fmt.Printf("SumSlice is %d\n", SumSlice(sliceArr))
	fmt.Printf("sliceX modified result is %d\n", sliceArr)

	sliceX := sliceArr[1:3]
	fmt.Printf("sliceX len is %d, sliceX cap is %d\n", len(sliceX), cap(sliceX))
	b := []byte{'g', 'o', 'l', 'a', 'n', 'g'}
	fmt.Printf("b[1:4] is %s  b[:2] is %s  b[2:] is %s  b[:] is %s\n", b[1:4], b[:2], b[2:], b[:])

	s1 := make([]string, 5, 10)
	s1 = s1[2:4]
	fmt.Printf("s1 len is %d, s1 cap is %d\n", len(s1), cap(s1))

	s2 := new([100]int)[:50]
	fmt.Printf("s2 is %p\n", s2)
}

func Sum(a *[3]float64) (sum float64) {
	for _, f := range a {
		sum += f
	}
	return
}

func SumSlice(a []int) (sum int) {
	for i, v := range a {
		sum += v
		if i == 1 {
			a[i] = 100
		}
	}
	return
}
